#!/usr/bin/env bash
# EXEC_STD_OUT=${HOME}/tmp/log.txt

YESTERDAY=`date -d last-day +%Y%m%d`

echo "昨天日期: "${YESTERDAY}
EXEC_STD_OUT=${HOME}/tmp/log.txt.${YESTERDAY}

JAVA_BIN="${HOME}/tmp/"

cd ${JAVA_BIN}

PATH1="${HOME}/tmp/00/${YESTERDAY}/*.*"
PATH2="${HOME}/tmp/01/${YESTERDAY}/*.*"

FILE_LIST1="${HOME}/tmp/filelist1"
FILE_LIST2="${HOME}/tmp/filelist2"

# 轮询判断目录下的文件数是否满足要求
FILE_COUNT=`ls ${PATH2} | wc -l`

while(( $FILE_COUNT < 5 ))
do
    echo `date +%Y%m%d%%H%M%S`" 时文件数："${FILE_COUNT}
    # 睡眠5s，时间长度，后面可接 s、m、h 或 d，其中 s 为秒，m 为 分钟，h 为小时，d 为日数
    sleep 5s
    FILE_COUNT=`ls ${PATH2} | wc -l`
done

`ls ${PATH1} > ${FILE_LIST1}`
`ls ${PATH2} > ${FILE_LIST2}`

JAVA_EXEC1="/bin/bash -x ${HOME}/tmp/crontab1.bash"
JAVA_EXEC2="/bin/bash -x ${HOME}/tmp/crontab2.bash"

# 输出执行命令
echo exec ${JAVA_EXEC1}
echo exec ${JAVA_EXEC2}

# 后台执行命令
nohup ${JAVA_EXEC1} > ${EXEC_STD_OUT} 2>&1 &
nohup ${JAVA_EXEC2} > ${EXEC_STD_OUT} 2>&1 &


